-- 格式要UTF8-BOM
local TWaryLua = require "TWaryLua";
local json = require "json"
local all_info = require "lua.all_info"
local genpwd = require "lua.GenPassword"
local initData = require "1";


--------------------------------------------------------------------------------------------------------------------------------------------------------

local content = ""

content = content .. "\nAlter LOGIN sa ENABLE "
content = content .. "\nGO"
content = content .. "\nAlter LOGIN sa WITH PASSWORD = '" .. genpwd.sa_pass .."'"
content = content .. "\nGO"
content = content .. "\n"
content = content .. "\nAlter LOGIN cpp_app ENABLE "
content = content .. "\nGO"
content = content .. "\nAlter LOGIN cpp_app WITH PASSWORD = '" .. genpwd.cpp_pass .."'"
content = content .. "\nGO"
content = content .. "\n"
content = content .. "\nAlter LOGIN iis_app ENABLE "
content = content .. "\nGO"
content = content .. "\nAlter LOGIN iis_app WITH PASSWORD = '" .. genpwd.iis_pass .."'"
content = content .. "\nGO"
content = content .. "\n"
content = content .. "\nAlter LOGIN java_app ENABLE "
content = content .. "\nGO"
content = content .. "\nAlter LOGIN java_app WITH PASSWORD = '" .. genpwd.java_pass .."'"
content = content .. "\nGO"
content = content .. "\n"
content = content .. "\nAlter LOGIN node_login_app ENABLE "
content = content .. "\nGO"
content = content .. "\nAlter LOGIN node_login_app WITH PASSWORD = '" .. genpwd.node_login_pass .."'"
content = content .. "\nGO"
content = content .. "\n"
content = content .. "\nAlter LOGIN node_pay_app ENABLE "
content = content .. "\nGO"
content = content .. "\nAlter LOGIN node_pay_app WITH PASSWORD = '" .. genpwd.node_pay_pass .."'"
content = content .. "\nGO"



content = content .. [[

--更改数据库属主
ALTER AUTHORIZATION ON DATABASE::WHJHAccountsDB TO sa
ALTER AUTHORIZATION ON DATABASE::WHJHActivityDB TO sa
ALTER AUTHORIZATION ON DATABASE::WHJHAgentDB TO sa
ALTER AUTHORIZATION ON DATABASE::WHJHDataBackupDB TO sa
ALTER AUTHORIZATION ON DATABASE::WHJHGameScoreDB TO sa
ALTER AUTHORIZATION ON DATABASE::WHJHNativeWebDB TO sa
ALTER AUTHORIZATION ON DATABASE::WHJHPlatformDB TO sa
ALTER AUTHORIZATION ON DATABASE::WHJHPlatformManagerDB TO sa
ALTER AUTHORIZATION ON DATABASE::WHJHRecordDB TO sa
ALTER AUTHORIZATION ON DATABASE::WHJHTreasureDB TO sa

--所有用户映射为Activity库的owner
use WHJHActivityDB
go
create user cpp_app for login cpp_app with default_schema=dbo
go
exec sp_addrolemember 'db_owner', 'cpp_app'
go

use WHJHActivityDB
go
create user iis_app for login iis_app with default_schema=dbo
go
exec sp_addrolemember 'db_owner', 'iis_app'
go

use WHJHActivityDB
go
create user node_login_app for login node_login_app with default_schema=dbo
go
exec sp_addrolemember 'db_owner', 'node_login_app'
go

use WHJHActivityDB
go
create user node_pay_app for login node_pay_app with default_schema=dbo
go
exec sp_addrolemember 'db_owner', 'node_pay_app'
go


]]



content = content .. "\n--更改gameserver连接数据库信息"
content = content .. "\nupdate [WHJHPlatformDB].[dbo].[GameGameItem] "
content = content .. "\n    set DataBaseAddr = '" .. all_info.sql_address_private .. "'"
content = content .. "\nupdate [WHJHPlatformDB].[dbo].[GameRoomInfo] "
content = content .. "\n    set DataBaseAddr = '" .. all_info.sql_address_private .. "',ServiceMachine = '" .. all_info.game_server_guid .. "'"
content = content .. "\n"
content = content .. "\nupdate [WHJHPlatformDB].[dbo].[DataBaseInfo] "
content = content .. "\n    set DBAddr='" .. all_info.sql_address_private .. "' where DBInfoID != 1"
content = content .. "\nupdate [WHJHPlatformDB].[dbo].[DataBaseInfo] "
content = content .. "\n    set DBPassword='" .. TWaryLua.XorEncrypt(genpwd.cpp_pass) .. "'"
content = content .. "\n"
content = content .. "\n"
content = content .. "\n--更改系统库信息"
content = content .. "\nupdate [WHJHAccountsDB].[dbo].[SystemStatusInfo] "
content = content .. "\n    set StatusString='" .. initData.name .."后台管理' "
content = content .. "\n    where StatusName='system_title'  --StatusString要改"
content = content .. "\nupdate [WHJHAccountsDB].[dbo].[SystemStatusInfo] "
content = content .. "\n    set StatusValue=1 "
content = content .. "\n    where StatusName='VIPShareGrade'"
content = content .. "\n"
content = content .. "\n--更改存储桶"
content = content .. "\nupdate [WHJHNativeWebDB].[dbo].[ConfigInfo] "
content = content .. "\n    set Field1='oss-cn-shenzhen',Field2='" .. initData.oss_accesskey_id .. 
	"',Field3='" .. initData.oss_accesskey_secret .. 
	"',Field4='" .. initData.xxxx .."image',Field6='".. initData.xxxx .. "image.oss-cn-shenzhen.aliyuncs.com' "

content = content .. "\n    where ConfigKey='fileSaveConfig'   --Field2,3,4,6要改"


TWaryLua.SaveToFile("./sql/改密码脚本.txt", content)
print(content)
